/*
 * Part of the ACID Project
 * Developed in 2011 by Morgan Taschuk
 */
package acid.spring.jdbc;

import acid.spring.TissueService;
import acid.spring.config.AcidConfiguration;
import acid.spring.jdbc.services.JdbcTissueService;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

/**
 *
 * @author morgan
 */
@Configuration
public class JdbcConfiguration extends AcidConfiguration
{

//    @Bean
//    public TissueService tissueService()
//    {
//        return new JdbcTissueService();
//    }

    @Bean
    public JdbcTemplate jdbcTemplate()
    {
        DataSource ds = dataSource(); // this comes from the parent class
        return new JdbcTemplate(ds);
    }

    @Bean
    public PlatformTransactionManager transactionManager()
    {
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
        dataSourceTransactionManager.setDataSource(this.dataSource());
        return dataSourceTransactionManager;
    }

    @Bean
    public TransactionTemplate transactionTemplate()
    {
        TransactionTemplate tt = new TransactionTemplate();
        tt.setTransactionManager(this.transactionManager());
        return tt;
    }
}
